<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            安灯历史记录
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">

        <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
            <ul class="aui-list aui-form-list">
                <!-- <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 200px">异常记录编码</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="异常记录编码" id="code" value="" onclick="getIdSelector();" />
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 200px">发起时间起</div>
                        <div class="aui-list-item-input" onclick="showTime();">
                            <input type="text" placeholder="选择时间" class="aui-input" id="startTime">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 200px">发起时间止</div>
                        <div class="aui-list-item-input" onclick="showTime2();">
                            <input type="text" placeholder="选择时间" class="aui-input" id="endTime">
                        </div>
                    </div>
                </li> -->
            </ul>
        </div>
        <!-- <div class="aui-btn aui-btn-info" style="width:45%;margin-left:4%;" onclick="swipeCard()">查看记录</div>
        <div class="aui-btn aui-btn-info" style="width:45%;margin-left:2%;" onclick="doSearch()">查询</div> -->

        <div
            style="background-color:white; width: 100%;margin-top:2%;overflow-x: auto;-webkit-overflow-scrolling:touch;">
            <table class="table" style='width:2640px;' id="table1">
                <tbody style="display:block">
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 15px;font-weight: bold;">
                        <td algin='center' style='width:40px;'></td>
                        <td algin='center' style='width:200px;'>节点状态</td>
                        <td algin='center' style='width:200px;'>操作人</td>
                        <td algin='center' style='width:200px;'>操作时间</td>
                        <td algin='center' style='width:200px;'>创建时间</td>
                        <td algin='center' style='width:200px;'>异常内容编码</td>
                        <td algin='center' style='width:200px;'>异常内容名称</td>
                        <td algin='center' style='width:200px;'>处理措施编码</td>
                        <td algin='center' style='width:200px;'>处理措施名称</td>
                        <td algin='center' style='width:200px;'>异常原因编码</td>
                        <td algin='center' style='width:200px;'>异常原因名称</td>
                        <td algin='center' style='width:200px;'>物料编码</td>
                        <td algin='center' style='width:200px;'>工序编码</td>
                        <td algin='center' style='width:200px;'>备注</td>
                    </tr>
                </tbody>
            </table>
            <table class="table" style='width:2640px;' id="table">
                <tbody id="tbodyHtml" style="display: block;height: 500px;overflow-y: scroll;">
                </tbody>
            </table>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    var ids = "";
    //初始化
    apiready = function () {
        ids = api.pageParam.id;  // 获取 'id' 字段的值
        // $("#code").focus();
        // idSelector = "code";
        // //获取当前日期
        // crateDate()
        doSearch();
    }

    //获取当前日期
    function crateDate() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        $("#startTime").val(year + "-" + month + "-" + day + " 00:00:00");
        $("#endTime").val(year + "-" + month + "-" + day + " 23:59:00");
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    function swipeCard() {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        check.each(function () {
            count++;
        });

        //选中行不为1
        if (count != 1) {
            api.toast({
                msg: '请选择一条数据！',
                duration: 3000
            });
            return;
        }
        var ids = "";
        var taskId = "";
        var exceptionTypeCode = "";
        var exceptionTypeName = "";
        var exceptionContentCode = "";
        var exceptionContentName = "";
        var exceptionRemark = "";
        var opCode = "";
        var mrlCode = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            var sysid = row.find("[name='sysid']").html();
            taskId = row.find("[name='taskId']").html();               // 获取任务ID
            exceptionTypeCode = row.find("[name='exceptionTypeCode']").html(); // 获取异常类型编码
            exceptionTypeName = row.find("[name='exceptionTypeName']").html(); // 获取异常类型名称
            exceptionContentCode = row.find("[name='exceptionContentCode']").html(); // 获取异常内容编码
            exceptionContentName = row.find("[name='exceptionContentName']").html(); // 获取异常内容名称
            exceptionRemark = row.find("[name='exceptionRemark']").html(); // 获取异常描述
            opCode = row.find("[name='opCode']").html();             // 获取工序编码
            mrlCode = row.find("[name='mrlCode']").html();           // 获取物料编码
            ids += "" + sysid + ","
        });

        if (ids) {
            ids = ids.substring(0, ids.length - 1);
        }
        console.log(ids)

        api.openWin({
            name: 'andon_history_detail',
            url: 'andon_history_detail.html',
            pageParam: {
                name: "andon_history",
                id: ids,
                taskId: taskId,
                exceptionTypeCode: exceptionTypeCode,
                exceptionTypeName: exceptionTypeName,
                exceptionContentCode: exceptionContentCode,
                exceptionContentName: exceptionContentName,
                exceptionRemark: exceptionRemark,
                opCode: opCode,
                mrlCode: mrlCode,
            }
        });
    }

    function showTime() {
        var moduleTimer = api.require('moduleTimer');
        moduleTimer.showTimer({
            startTime: '2000-01-01 00:00:00',//可选择的起始时间
            endTime: '2099-12-31 23:59:59',//可选择的结束时间
            timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
            selColor: '#079962'//选中的颜色值
        }, function (ret, err) {
            var actualBeginDate = ret;
            var text = document.getElementById("startTime");
            text.value = actualBeginDate;
        });
    }

    function showTime2() {
        var moduleTimer = api.require('moduleTimer');
        moduleTimer.showTimer({
            startTime: '2000-01-01 00:00:00',//可选择的起始时间
            endTime: '2099-12-31 23:59:59',//可选择的结束时间
            timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
            selColor: '#079962'//选中的颜色值
        }, function (ret, err) {
            var actualBeginDate = ret;
            var text = document.getElementById("endTime");
            text.value = actualBeginDate;
        });
    }

    //查询
    function doSearch() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAndonHistoryDetailList";
        var data = {
            values: {
                sysid: ids,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                        html += "<td style='width:40px;'><input name='sub' type='checkbox' /></td>";
                        html += "<td name='nodeState' style='width:200px;'>" + (list[i].nodeState || "") + "</td>";
                        html += "<td name='modifyId' style='width:200px;'>" + (list[i].modifyId || "") + "</td>";
                        html += "<td name='modifyDate' style='width:200px;'>" + (list[i].modifyDate || "") + "</td>";
                        html += "<td name='createDate' style='width:200px;'>" + (list[i].createDate || "") + "</td>";
                        html += "<td name='exceptionContentCode' style='width:200px;'>" + (list[i].exceptionContentCode || "") + "</td>";
                        html += "<td name='exceptionContentName' style='width:200px;'>" + (list[i].exceptionContentName || "") + "</td>";
                        html += "<td name='exceptionMeasureCode' style='width:200px;'>" + (list[i].exceptionMeasureCode || "") + "</td>";
                        html += "<td name='exceptionMeasureName' style='width:200px;'>" + (list[i].exceptionMeasureName || "") + "</td>";
                        html += "<td name='exceptionReasonCode' style='width:200px;'>" + (list[i].exceptionReasonCode || "") + "</td>";
                        html += "<td name='exceptionReasonName' style='width:200px;'>" + (list[i].exceptionReasonName || "") + "</td>";
                        html += "<td name='mrlCode' style='width:200px;'>" + (list[i].mrlCode || "") + "</td>";
                        html += "<td name='opCode' style='width:200px;'>" + (list[i].opCode || "") + "</td>";
                        html += "<td name='remark' style='width:200px;'>" + (list[i].remark || "") + "</td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    function submit() {
        api.openWin({
            name: 'andon_launch_detail',
            url: 'andon_launch_detail.html',
            pageParam: {
                name: "andon_launch",
            }
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

<style>
    .c1 {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .5);
        z-index: 99;
        margin-top: 0%;
    }

    .c2 {
        background-color: white;
        position: fixed;
        width: 400px;
        height: 300px;
        top: 50%;
        left: 50%;
        z-index: 100;
        margin-top: -125px;
        margin-left: -200px;
        padding-top: 2%;
        padding-left: 2%;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }
</style>

</html>